package com.itheima.exer.homework.hw1011.tickets;

public class Ticket implements Runnable {
    private static final Object object = new Object();
    private static Integer ticket = 100;

    @Override
    public void run() {
        while (true) {
            synchronized (object) {
                if (ticket <= 0) {
                    break;
                } else {
                    try {
                        Thread.sleep(50);
                        System.out.println(Thread.currentThread().getName() + "买出的第" + ticket + "张票");
                        ticket--;
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }
            }
        }

    }
}
